/*
 * Copyright 2018- The Pixie Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

syntax = "proto3";

package px.services;

option go_package = "vzconnpb";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "src/api/proto/uuidpb/uuid.proto";

service VZConnService {
  // Registers a new Vizier deployment and returns a cluster ID.
  // Needs to have an X-API-KEY metadata with the Vizier deploy key.
  rpc RegisterVizierDeployment(RegisterVizierDeploymentRequest)
      returns (RegisterVizierDeploymentResponse);
  rpc NATSBridge(stream V2CBridgeMessage) returns (stream C2VBridgeMessage);
}

// V2CBridgeMessage is the message sent from vizier to cloud to bridge their respective NATS
// instances.
message V2CBridgeMessage {
  // The topic is the intended topic on the cloud side. All published cvmsgspb will automatically
  // become a topic under the subpath /vizier/<vizier_id>/<topic>.
  string topic = 1;
  // This is an opaque monotonically increasing ID that changes when ever the cloud connector
  // restarts.
  int64 session_id = 2;
  // The contents of the actual message.
  google.protobuf.Any msg = 3;
}

// C2VBridgeMessage is the message sent from cloud to vizier to bridge their respective NATS
// instances.
message C2VBridgeMessage {
  // The topic where this message will be published. All cvmsgspb will be published under the
  // sub-path: /cloud-response/<topic>.
  string topic = 1;
  // The contents of the actual message.
  google.protobuf.Any msg = 2;
}

message RegisterVizierDeploymentRequest {
  // The UID of the K8s cluster. This is typically the UI of the kube-system namespace.
  // We assume this is globally unique.
  string k8s_cluster_uid = 1 [ (gogoproto.customname) = "K8sClusterUID" ];
  // The recommended name for the cluster. Modifications may be made to the recommended name to
  // perform deduplication. If no name is specified, a random name will be generated.
  string k8s_cluster_name = 2 [ (gogoproto.customname) = "K8sClusterName" ];
  reserved 3;  // DEPRECATED
}

// RegisterVizierDeploymentResponse returns the registration status. It either will include the
// assigned vizier_id or a GRPC error will be returned.
message RegisterVizierDeploymentResponse {
  // The ID for this Vizier.
  uuidpb.UUID vizier_id = 1 [ (gogoproto.customname) = "VizierID" ];
  // The name for this Vizier.
  string vizier_name = 2;
}
